<template>
  <el-table :data="tableData" style="width: 100%" border>
    <el-table-column prop="grade" label="年级"> </el-table-column>
    <el-table-column prop="filesName" label="评分细则"> </el-table-column>
    <el-table-column label="操作" width="100">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small"
          >下载文件</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>
<script>
export default {
  name: "score",
  data() {
    return {
      tableData: [],
    };
  },
  created() {
    this.getData();
  },
  methods: {
    async getData() {
      const userInfo = JSON.parse(localStorage.getItem("userInfo"));
      const { data } = await this.$request.get("/getTVlist/getTV", {
        params: {
          // page:page,
          // pagesize:pagesize,
        },
      });
      if (data.code !== 200) return;
      data.data.forEach((item) => {
        if (item.SecondaryCollege === userInfo.SecondaryCollege) {
          this.tableData = item.rulesList;
        }
      });
    },
    async handleClick(row) {
      console.log("row==", row);
      const data = await this.$request.get('/files/getIFilesData?url=' + row.url + '&' + 'filesName=' + row.filesName,
            // {
            //     params: {
            //         // page:page,
            //         // pagesize:pagesize,
            //         // collectionName: url
            //         url: row.url,
            //         filesName: row.filesName
            //     }
            // },
            {
                responseType: 'blob',
                // headers:{
                //     'content-type':'application/actet-stream',
                // }
            }
        )
        // if (data) {
        //     const a = document.createElement('a')
        //     // a.href = url
        //     a.type='text/javascript'
        //     a.download=row.filesName
        // }
        // const type = data.headers['content-type']
        const blob = new Blob([data.data], { type: data.headers['content-type'] + ';charset=utf-8' })
        console.log("blob--==", blob);
        const url = window.URL.createObjectURL(blob)
        console.log("url00---==", url);
        const a = document.createElement('a')
        a.href = url
        a.download = row.filesName
        // document.body.appendChild(a)
        a.click()
        // a.remove()
        window.URL.revokeObjectURL(url)
        console.log("row==", data);
    },
  },
};
</script>
<style lang="scss" scoped>
</style>